/*
 * InitObj.h
 *
 *  Created on: Nov 24, 2011
 *      Author: xwq
 */
#ifndef XZ_CLOG_WYL_H_
#define XZ_CLOG_WYL_H_

#include <stdarg.h>
#include <pthread.h>
#include <android/log.h>
#include "../mutex/tmutex.h"


#define TAG "NMD050-jni" 													// 这个是自定义的LOG的标识
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,TAG ,__VA_ARGS__) 	// 定义LOGD类型
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO,TAG ,__VA_ARGS__) 	// 定义LOGI类型
#define LOGW(...) __android_log_print(ANDROID_LOG_WARN,TAG ,__VA_ARGS__) 	// 定义LOGW类型
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,TAG ,__VA_ARGS__) 	// 定义LOGE类型
#define LOGF(...) __android_log_print(ANDROID_LOG_FATAL,TAG ,__VA_ARGS__) 	// 定义LOGF类型

#define 					MAX_PATH  						255

#define                     NO_LOG_LEVEL					0x0000 //不打印日志
#define						ERROR_LOG_LEVEL				    0x0001 //错误信息
#define						API_LOG_LEVEL					0x0002 //接口日志
#define						ACCOUNT_LOG_LEVEL               0x0004 //账号密钥敏感信息
#define                     MESSAGE_LOG_LEVEL               0x0008 //报文日志

class CLog
{
public:
	CLog();
	~CLog();
	static CLog * GetInstance();
	int WriteLog(int ucLoglevel,const char * Format,...);
	void SetLogInfo(int LogLevel,const char * pFileLocation,const char * pFileName, int iMaxSize, int iKeepingDate);
private:
	int mkdir_r(const char *path);
	int GetModuleFilename(char* sModuleName, char* sFileName, int nSize);
	int DeleteExpiredFile(const char *strDirPath, char * strFileName);
	char m_strWorkPath[MAX_PATH + 1];		//Dll本身路径
	bool bLogLevel;

	char m_sFileName[MAX_PATH];				//LOG文件名
	int m_StoreDayNum;						//日志保存天数
	int m_iMaxSize;							//日志大小，默认100M
	unsigned short m_bLogLevel;             //日志级别
	static CLog * m_pInstance;				//日志类指针

	class CGarbo {
	public:
		~CGarbo() {
			if (CLog::m_pInstance)
				delete CLog::m_pInstance;
		}
	};

	static CGarbo Garbo;
	typedef ThreadMutex MUTEX_TYPE;
	MUTEX_TYPE m_mtx;
};

#endif /* XZ_CLOG_WYL_H_ */
